program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement=^element;
  element=record
    value: integer;
    next: pelement;
  end;
procedure AddStart(var head: pelement; num:integer);
var
  tmp: pelement;
begin
  tmp:=head;
  New(head);
  head^.next:=tmp;
  head^.value:=num;
end;
function DeleteStart(var head: pelement): integer;
var
  tmp: pelement;
begin
  if (head<> nil) then
  begin
    tmp:=head^.next;
    DeleteStart:=head^.value;
    Dispose(head);
    head:=tmp;
  end;
end;
procedure print(head: pelement);
var
  current: pelement;
begin
  current:=head;
  while(current<> nil) do
  begin
    Writeln(current^.value);
    current:=current^.next;
  end;
end;
procedure AddEnd(var head: pelement; num: Integer);
var
  current: pelement;
begin
  if (head<>nil) then
  begin
    current:=head;
    while(current^.next<>nil) do
      current:=current^.next;
    New(current^.next);
    current^.next^.value:=num;
    current^.next^.next:=nil;
  end;
  if (head=nil) then
    AddStart(head, num);
end;
function DeleteEnd (var head:pelement):integer;
var
  current, tmp: pelement;
begin
  if (head <> nil) then
  begin
    current:=head;
    while(current^.next <> nil) do
    begin
      tmp:=current;
      current:=current^.next;
    end;
    DeleteEnd:=current^.value;
    tmp^.next:=nil;
    Dispose(current);
  end;
end;
var
  head: pelement;
  fin: textfile;
  n, i, num: integer;
begin
  AssignFile (fin, 'input.txt');
  Reset (fin);
  Readln (fin, n);
  head:=nil;
  for i:= 0 to n-1 do
  begin
    Readln (fin, num);
    AddStart (head, num);
  end;
  DeleteEnd (head);
  print(head);
  for i:= 0 to n-1 do
    DeleteStart (head);
  Closefile (fin);
  readln;
end.
 